package com.ruoyi.system.domain.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author nanyang
 */
@Data
public class TInterfaceVo {

    private Long id;

    private Long parentId;

    private String ancestors;

    private String name;

    private Integer orderNum;

    @ApiModel("TInterfaceVo - Result")
    @Data
    public static class Result{
        @ApiModelProperty("id")
        private Long id;
        @ApiModelProperty("分类ID")
        private Long categoryId;
        @Excel(name = "接口名称")
        @ApiModelProperty("接口名称")
        private String name;
        @Excel(name = "接口URI")
        @ApiModelProperty("接口URI")
        private String uri;

        @ApiModelProperty("请求方法(1GET、2POST、3PUT、4DELETE、5PATCH)")
        private Byte method;
        @Excel(name = "CODE")
        @ApiModelProperty("CODE")
        private String code;
        @Excel(name = "Content-Type")
        @ApiModelProperty("Content-Type")
        private String contentType;
        @Excel(name = "输入参数")
        @ApiModelProperty("输入参数")
        private String inputParam;
        @Excel(name = "入参示例")
        @ApiModelProperty("入参示例")
        private String input;
        @Excel(name = "输出参数")
        @ApiModelProperty("输出参数")
        private String outputParam;
        @Excel(name = "出参示例")
        @ApiModelProperty("出参示例")
        private String output;
        @Excel(name = "排序")
        @ApiModelProperty("排序")
        private String sort;
        @Excel(name = "禁用启用状态（0正常 1暂停）")
        @ApiModelProperty("禁用启用状态（0正常 1暂停）")
        private Byte status;
        @JsonIgnore
        private Byte delFlag;

        @ApiModelProperty("创建人")
        private String createBy;
        @ApiModelProperty("创建时间")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private Date createTime;
        @ApiModelProperty("修改人")
        private String updateBy;
        @ApiModelProperty("修改时间")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private Date updateTime;
        @JsonIgnore
        private String remark;

        @Excel(name = "分类祖级列表")
        @ApiModelProperty("分类祖级列表")
        private String ancestors;
        @Excel(name = "分类名称")
        @ApiModelProperty("分类名称")
        private String categoryName;
        @Excel(name = "请求方法")
        private String methodString;
        public String getMethodString() {
            if (method != null) {
                //1GET、2POST、3PUT、4DELETE、5PATCH
                if (method == 1) {
                    return "GET";
                }
                if (method == 2) {
                    return "POST";
                }
                if (method == 3) {
                    return "PUT";
                }
                if (method == 4) {
                    return "DELETE";
                }
                if (method == 5) {
                    return "PATCH";
                }
            }
            return "";
        }

        public List<Long> getAncestors() {
            if (StrUtil.isEmpty(ancestors)) {
                return null;
            }
            return Arrays.stream(ancestors.split(",")).map(Long::parseLong).collect(Collectors.toList());
        }
    }
}
